Skip to content

feat: add get_processes() for GET /v1/system/processes; deprecate get_procs() - #533

Merged
jmwoliver merged 5 commits into
mainfrom
feat/get-processes
Nov 9, 2026
Merged

jmwoliver merged 5 commits into
mainfrom
feat/get-processes

Conversation

@jmwoliver

@jmwoliver jmwoliver commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #531. Fixes #532. Builds on #530 (merged); rebased onto main.

Connect 2026.11.0 adds GET /v1/system/processes (posit-dev/connect#47671), a supported replacement for the internal GET /metrics/procs. This PR wraps it and deprecates get_procs().

Changes

  • New get_processes(src, content_guid = NULL, owner_guid = NULL, hostname = NULL)
    • Calls GET /v1/system/processes with Accept: text/csv and the endpoint's three filters (ANDed, same as the server).
    • Returns a tibble with the endpoint's 13 columns, typed: pid integer, cpu_current double, ram fs_bytes, start_time/heartbeat POSIXct. Every CSV column is read as character first, so types don't depend on which values are present. Empty results are a typed, zero-row tibble with the same columns. Columns added by later Connect versions are kept.
    • Fallback: if the v1 call returns a 404 without a Connect error code (the usual endpoint_does_not_exist() pattern), it calls /metrics/procs instead. It renames app_* → content_*, drops app_id, and turns the old endpoint's placeholders ("unknown", "unknown host", "", pid 0) into NA, matching the v1 endpoint's nulls. Filters are applied client-side, and owner_guid is resolved through GET /v1/content?owner_guid=. A 404 with a code (e.g. an unknown content_guid) is raised as an error, not treated as a reason to fall back.
  • get_procs() is deprecated with lifecycle::deprecate_warn("0.13.0", "get_procs()", "get_processes()") and moved to @keywords internal. The request logic now lives in an internal fetch_legacy_procs(), which the fallback calls directly, so get_processes() never raises the deprecation warning.
  • Fixes get_procs() @return docs don't match returned columns, and pid column is the row index #532 along the way, since the fallback shares this code:
    • get_procs() used imap() as if the response were keyed by PID. Current Connect returns an array, so pid was the row index. It now returns the server's pid. The old keyed-by-PID shape is still handled.
    • start_time/heartbeat are now parsed as datetimes.
    • The @return docs now list the columns the endpoint actually returns.
  • endpoint_does_not_exist() now passes encoding = "UTF-8". Without it, falling back on old Connect's text/plain 404 printed No encoding supplied: defaulting to UTF-8.. This affects the other fallbacks that use the helper too.

Verification

No published image has the endpoint yet: today's connect-preview:daily was built from 39012c1, which predates the merge (git merge-base --is-ancestor says no). I built the Connect server from posit-dev/connect@5f81b53 (current main, which includes #47671) in Connect's compilation container, and layered it onto connect-preview:daily. Then I ran the same tests against that build and against the current release, 2026.10.0, both started with with-connect.

Integration tests, tests/integrated with filter = "get" and load_package = "installed". The new test deploys a dependency-free Python WSGI API, sets min_processes = 1, and checks the columns, types, values, each filter, and that get_procs() is deprecated and returns the same process with the real pid:

Server Result
2026.11.0-dev+main.5f81b53189 (has the endpoint) [ FAIL 0 | WARN 0 | SKIP 1 | PASS 75 ]
2026.10.0 (fallback) [ FAIL 0 | WARN 0 | SKIP 1 | PASS 75 ]

(The skip is the existing content_list_by_tag "not yet tested" placeholder.)

Requests made, captured by tracing httr::GET during a script run against each server. New Connect makes one CSV request per call:

GET /__api__/v1/system/processes?content_guid=d5ac9df4-bed4-4631-a488-89182b57e96d  [Accept: text/csv]  -> 200
GET /__api__/v1/system/processes?owner_guid=bf03711b-362c-4bdd-8c5e-4cfc94f23414  [Accept: text/csv]  -> 200
GET /__api__/v1/system/processes?hostname=762b4492c8d2  [Accept: text/csv]  -> 200
GET /__api__/v1/system/processes?hostname=no-such-host  [Accept: text/csv]  -> 200
GET /__api__/metrics/procs  [Accept: application/json, text/xml, application/xml, */*]  -> 200

Connect 2026.10.0 gets a 404 on v1, then falls back:

GET /__api__/v1/system/processes?content_guid=0bd6d2c0-3e2b-49ba-b784-f1c4fa8a3db5  [Accept: text/csv]  -> 404
GET /__api__/metrics/procs  [Accept: application/json, text/xml, application/xml, */*]  -> 200
GET /__api__/v1/system/processes?owner_guid=7fabf8f2-d5f8-4917-a980-51ad759b5069  [Accept: text/csv]  -> 404
GET /__api__/metrics/procs  [Accept: application/json, text/xml, application/xml, */*]  -> 200
GET /__api__/v1/content?owner_guid=7fabf8f2-d5f8-4917-a980-51ad759b5069  [Accept: application/json, text/xml, application/xml, */*]  -> 200
GET /__api__/v1/system/processes?hostname=963f2302a45a  [Accept: text/csv]  -> 404
GET /__api__/metrics/procs  [Accept: application/json, text/xml, application/xml, */*]  -> 200
GET /__api__/v1/system/processes?hostname=no-such-host  [Accept: text/csv]  -> 404
GET /__api__/metrics/procs  [Accept: application/json, text/xml, application/xml, */*]  -> 200
GET /__api__/metrics/procs  [Accept: application/json, text/xml, application/xml, */*]  -> 200

On both servers the result had the same 13 columns and classes:

content_guid content_name  content_url       run_as         type          pid     hostname      job_key        image   start_time    heartbeat  cpu_current          ram
 "character"  "character"  "character"  "character"  "character"    "integer"  "character"  "character"  "character"    "POSIXct"    "POSIXct"    "numeric"   "fs_bytes"

get_procs() on both servers warns:

`get_procs()` was deprecated in connectapi 0.13.0.
ℹ Please use `get_processes()` instead.

It also returns the same pid as get_processes() (548 on the new build, 610 on 2026.10.0) instead of 1.

I also checked the raw responses with curl. New Connect returns a header-only CSV (text/csv; charset=utf-8) when nothing is running, and {"code":4,...} with a 404 for an unknown content_guid. 2026.10.0 returns 404 page not found as text/plain for /v1/system/processes.

Unit tests (tests/testthat/test-processes.R, 104 expectations) use MockConnect, with a small subclass that records the headers and query of each request. They cover:

  • the Accept: text/csv header and filter query params
  • CSV quoting, nulls, and types
  • zero-row results on both paths
  • extra columns from the server
  • no fallback on a 404 that has a code
  • the fallback giving output identical to the v1 path for the same processes
  • client-side filters, including owner_guid
  • get_procs(): deprecation, real pid, and the old keyed-by-PID format

The test that the fallback doesn't warn passes class = "lifecycle_warning_deprecated", because expect_no_warning() ignores deprecation warnings by default. I confirmed it fails if the fallback is changed to call get_procs().

  • Full unit suite: 0 failures
  • devtools::lint() (same as CI): 0 lints
  • R CMD check --no-manual: 0 errors, 0 warnings, 0 notes

Base automatically changed from docs/get-procs-ha-note to main November 6, 2026 19:02
get_processes() requests the v1 endpoint as CSV and supports its
content_guid, owner_guid, and hostname filters. On Connect versions
without it (404 with no error code), it falls back to the unversioned
/metrics/procs endpoint, maps the columns and placeholder values to the
v1 conventions, and applies the filters client-side.

get_procs() is deprecated in favor of get_processes(). The shared
request logic no longer goes through get_procs(), so the fallback does
not raise the deprecation warning. get_procs() now returns the server's
pid instead of the row index and parses its datetime columns (#532).

endpoint_does_not_exist() now passes an explicit encoding, so falling
back on a text/plain 404 no longer prints an encoding message.
jmwoliver and others added 2 commits November 6, 2026 15:31
Address review feedback on #533:

- On Connect without GET /v1/system/processes, an unknown content_guid
  or owner_guid now raises a 404, as the v1 endpoint does, instead of
  returning no processes. The fallback checks them with
  GET /v1/content/{guid} and GET /v1/users/{guid} before fetching
  /metrics/procs.
- Deprecate the Connect$procs() R6 method in favor of get_processes().
- Type the result once: the fallback path already calls
  type_processes(), so get_processes() no longer calls it again.
- The integration test stops its process with withr::defer(), so a
  failing expectation doesn't leave it running, and checks that
  unknown content and owner GUIDs are errors.

@nealrichardson nealrichardson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this, left a few suggestions

Comment thread R/get.R Outdated
}

#' Get Real-Time Process Data
#' Get running processes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we move all of this process code to a new processes.R? get.R seems like a catch-all and this has enough code to deserve its own I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Done: get_processes(), get_procs(), and their helpers are now in R/processes.R. The integration test has also moved out of tests/integrated/test-get.R into a new tests/integrated/test-processes.R, which matches the unit tests in tests/testthat/test-processes.R.

Comment thread R/get.R Outdated
# Give a processes table its documented column types, adding any missing
# columns so that empty results have the same shape as non-empty ones. Columns
# the server sends that we don't know about are kept at the end.
type_processes <- function(df) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do this in colClasses in read.csv() and get it all right from the start?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 I tried this. colClasses can only take over part of the typing, so I've left the typing in type_processes():

  • type_processes() also types the GET /metrics/procs fallback. That data comes from JSON with different types (for example, pid comes from the object's names as a string), so we need the function either way. Using colClasses for the CSV path would mean typing these columns in two places.
  • start_time/heartbeat can't be set there: colClasses = c(start_time = "POSIXct") silently drops the time from "2026-11-09T10:00:00Z" and keeps only the date. ram can't either, because there's no colClass for fs_bytes. Those columns would still need converting afterwards.
  • Columns not named in colClasses get their types guessed, so all-NA columns become logical. Naming a column the server doesn't send triggers a warning, so we'd also have to read the header first.

I've added a comment above parse_processes_csv() explaining this so it isn't a mystery later. If you still want pid/cpu_current/ram in colClasses for the CSV path, I can do that.

Comment thread R/get.R Outdated
# The v1 endpoint returns null for values Connect doesn't know, where the
# unversioned endpoint uses placeholders. Match the v1 endpoint, whose CSV
# output also cannot distinguish an empty string from null.
for (col in names(df)[vapply(df, is.character, logical(1))]) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you use purrr::map_chr() above, so map_lgl here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Done: switched to purrr::map_lgl(df, is.character).

Comment thread tests/integrated/test-get.R Outdated
test_that("get_procs works", {
scoped_experimental_silence()
proc_data <- get_procs(client)
# Deploy a dependency-free Python API and keep a process for it running, so

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this simpler than deploying something with R? Are we already deploying a shiny app above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Yes, it's simpler, and no, nothing deployed earlier keeps a process running. The other integration tests only deploy static content. The tests/testthat/examples/shiny fixture isn't used in the integration tests (test-get.R notes that "No shiny apps are deployed in integration tests").

To get a process to show up, the content has to keep a process running. On the R side that means Shiny or Plumber, so Connect would have to install those packages and their dependencies when deploying. The shiny fixture's manifest also pins R 3.6.3 and a long list of dependencies. The Python WSGI app with an empty requirements.txt installs nothing.

I've added a comment saying this above deploy_running_python_api(). It now also skips when the server has no Python installation, so it won't fail on images without one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Correction to my reply above: the Shiny fixture is used, in test-run-as.R, but that file skips on Connect > 2024.03.0 because the manifest pins R 3.6.3. The other integration tests deploy static and R Markdown content, which don't keep a process running. The reasoning holds: a Python WSGI app with an empty requirements.txt needs nothing installed. I've updated the code comment to match.

- Move get_processes(), get_procs() and helpers from R/get.R to
  R/processes.R, and their integration test to
  tests/integrated/test-processes.R.
- Use purrr::map_lgl() instead of vapply() in legacy_processes().
- Explain why parse_processes_csv() reads everything as character
  rather than typing columns via colClasses.
- Explain why the integration test deploys a Python API, and skip it
  when the server has no Python installation.
- get_processes() now errors on an empty content_guid, owner_guid, or
  hostname. Before, "" passed validation: the fallback's GUID checks
  requested the v1/content/ and v1/users/ list endpoints, so no 404 was
  raised, and the v1 endpoint was sent an empty query parameter.
- Correct the integration test comment on why it deploys a Python API:
  other tests also deploy R Markdown, and the Shiny example is used by
  test-run-as.R but pins R 3.6.3.
@jmwoliver

Copy link
Copy Markdown
Contributor Author

@nealrichardson Thanks for the review! I made some changes based on your feedback and replied to the things Claude felt were best to leave as-is. This should be good to go now, I'll merge this once CI passes.

@jmwoliver
jmwoliver merged commit 1bb9cad into main Nov 9, 2026
13 checks passed
@jmwoliver
jmwoliver deleted the feat/get-processes branch November 9, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_procs() @return docs don't match returned columns, and pid column is the row index Add get_processes() to wrap v1/system/processes

2 participants